<template>
  <a-drawer v-model:visible="LAYER.visible" :title="LAYER.title" :width="LAYER.width"
            :closable="LAYER.closable" :mask-closable="LAYER.maskClosable" :esc-to-close="LAYER.escToClose"
            :unmount-on-close="LAYER.unmountOnClose" :footer="LAYER.footer" :ok-text="LAYER.okText"
            :ok-loading="LAYER.okLoading" :cancel-text="LAYER.cancelText" :on-before-ok="onSubmit" @close="onCancel">

    <a-form ref="formRef" :model="formState" layout="vertical" :rules="RULES">
      <a-row :gutter="[12,12]">


        <a-col :span="12">
          <a-form-item label="商品代码" field="code">
            <a-input v-model="formState.code" placeholder="请填写商品代码" :disabled="isUpdate"/>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="商品名称" field="name">
            <a-input v-model="formState.name" placeholder="请填写品种名称"/>
          </a-form-item>
        </a-col>

        <a-col :span="12">
          <a-form-item label="猪仔品种" field="breed.code">
            <smart-dict v-model="formState.breed.code" placeholder="请填写猪仔档案" :url="ProductOptions.PigBreedOptions"/>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="喂养模式" field="mode">
            <smart-dict v-model="formState.mode" placeholder="请填写喂养模式" :url="DictOptions.PigstyKind" disabled />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="达到阶段" field="stage">
            <smart-dict v-model="formState.stage" placeholder="请填写所属阶段" is-radio :url="DictOptions.ProfileStage"/>
          </a-form-item>
        </a-col>



        <a-col :span="8">
          <a-form-item label="猪仔日龄" field="dayNum">
            <a-input-number v-model="formState.dayNum" :min="0" :max="1000" placeholder="请填写猪仔日龄">
              <template #append> <span style="width: 50px;">天</span> </template>
            </a-input-number>
          </a-form-item>
        </a-col>


        <a-col :span="8">
          <a-form-item label="销售价格" field="price">
            <a-input-number v-model="formState.price" placeholder="请填写销售价格">
              <template #append> <span style="width: 50px;">金币</span> </template>
            </a-input-number>
          </a-form-item>
        </a-col>

        <a-col :span="8">
          <a-form-item label="全额价格" field="fullPrice">
            <a-input-number v-model="formState.fullPrice" placeholder="请填写全额价格">
              <template #append> <span style="width: 50px;">金币</span> </template>
            </a-input-number>
          </a-form-item>
        </a-col>

        <a-col :span="8">
          <a-form-item label="全额认养赠送(鸡)" field="chicken">
            <a-input-number v-model="formState.chicken" placeholder="请填写认养赠送数量">
              <template #append> <span style="width: 50px;">只</span> </template>
            </a-input-number>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="全额认养赠送(蛋)" field="egg">
            <a-input-number v-model="formState.egg" placeholder="请填写认养赠送数量">
              <template #append> <span style="width: 50px;">颗</span> </template>
            </a-input-number>
          </a-form-item>
        </a-col>

        <a-col :span="8">
          <a-form-item label="包含月份(包含托管)" field="month">
            <a-input-number v-model="formState.month" placeholder="请填写包含月份">
              <template #append> <span style="width: 50px;">月</span> </template>
            </a-input-number>
          </a-form-item>
        </a-col>


        <a-col :span="8">
          <a-form-item label="钻石抵扣金额" field="deduction">
            <a-input-number v-model="formState.deduction" placeholder="请填写钻石抵扣金额">
              <template #append> <span style="width: 50px;">金币</span> </template>
            </a-input-number>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="猪仔预估重量" field="weight">
            <a-input-number v-model="formState.weight" placeholder="请求猪仔预估重量">
              <template #append> <span style="width: 50px;">重量</span> </template>
            </a-input-number>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="疾病险" field="insurance">
            <a-input-number v-model="formState.insurance" placeholder="请填写疾病险金额">
              <template #append> <span style="width: 50px;">金币</span> </template>
            </a-input-number>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="养猪险" field="accident">
            <a-input-number v-model="formState.accident" placeholder="请填写养猪险金额">
              <template #append> <span style="width: 50px;">金币</span> </template>
            </a-input-number>
          </a-form-item>
        </a-col>

        <a-col :span="8">
          <a-form-item label="备用金" field="reserveFund">
            <a-input-number v-model="formState.reserveFund" placeholder="请填写所需要备用金" >
              <template #append> <span style="width: 50px;">金币</span> </template>
            </a-input-number>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="猪仔库存" field="stock">
            <a-input-number v-model="formState.stock" :min="0" placeholder="请填写销售库存">
              <template #append> <span style="width: 50px;">只</span> </template>
            </a-input-number>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="销售状态" field="status">
            <smart-dict v-model="formState.status" placeholder="请填写销售状态" :url="DictOptions.ProfileStatus"/>
          </a-form-item>
        </a-col>


        <a-col :span="24">
          <a-form-item label="商品介绍" field="introduce">
            <a-textarea v-model="formState.introduce" auto-size placeholder="请填写商品介绍"/>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="是否促销" field="promotion">
            <a-radio-group v-model="formState.promotion"  >
              <a-radio :value="false">不促销</a-radio>
              <a-radio :value="true">促销</a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="是否可兑换" field="isExchange">
            <smart-bool v-model="formState.isExchange" true-text="可兑换" false-text="不可兑换"/>
          </a-form-item>
        </a-col>
        <a-col v-if="formState.promotion === true" :span="12">
          <a-form-item label="显示价格" field="showPrice">
            <a-input-number v-model="formState.showPrice" placeholder="请填写显示价格">
              <template #append> <span style="width: 50px;">金币</span> </template>
            </a-input-number>
          </a-form-item>
        </a-col>
        <a-col v-if="formState.promotion === true" :span="12">
          <a-form-item label="促销标语" field="msg">
            <a-input v-model="formState.msg" placeholder="请填写促销标语"/>
          </a-form-item>
        </a-col>


        <a-col :span="24">
          <a-form-item :label="`显示排序值 [ ${formState.sort} ]` " field="sort" tooltip="升序排序 显示值越小 显示越靠前">
            <a-slider v-model="formState.sort"/>
          </a-form-item>
        </a-col>


      </a-row>


    </a-form>
    <!--表单结束-->
  </a-drawer>
</template>

<script lang="ts" setup>


import {EditDrawer} from '@/libs/core'
import {DictOptions, ProductOptions} from '@/libs/options'
import {GOODS_EDIT,} from "../../resource/form";
import {ProductHttp} from '../../resource/http'


const props = defineProps({record: {type: Object, required: true}})
const emit = defineEmits(['cancel'])
const {BODY, RULES} = GOODS_EDIT

const {addGoods, updateGoods} = ProductHttp
const config = {tplRecord: BODY, rawRecord: props.record, rowKey: 'id', emit}
const service = new EditDrawer(config).setAddRequest(addGoods).setUpdateRequest(updateGoods)
const {formRef, formState, LAYER, isUpdate, onCancel, onSubmit} = service
LAYER.title = isUpdate ? '修改商品' : '新增商品'


</script>
